package stu.day25_day32.day25.all;

import java.util.*;

public class LeetCode102 {
    public List<List<Integer>> levelOrder(TreeNode root) {



        Queue<TreeNode> queue = new LinkedList<>();
        List<List<Integer>> all = new ArrayList<>();

        if(root==null){
            return all;
        }
        queue.add(root);



        while (!queue.isEmpty()){
            List<Integer> list = new ArrayList<>();
            int size = queue.size();
            for(int i =0;i<size;i++){
                TreeNode t = queue.poll();
                list.add(t.val);
                if(t.left!=null){
                    queue.offer(t.left);
                }
                if(t.right!=null){
                    queue.offer(t.right);
                }
            }
            all.add(list);
        }

        return all;


    }
}
